<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>SWM34S_LVGL7.11_SWMUI: C:/Users/DELL/Desktop/Commit/lvgl/SWM34S_LVGL7.11_SWMUI_20230515/APP/BSP/dev_systick.c 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">SWM34S_LVGL7.11_SWMUI<span id="projectnumber">&#160;V7.9</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.9.5 -->
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_0ca16891106f5a3e9ad635a0d6c5f98f.html">APP</a></li><li class="navelem"><a class="el" href="dir_4ca18d753a70f6eada20fde478bd3fc8.html">BSP</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">dev_systick.c</div></div>
</div><!--header-->
<div class="contents">
<a href="dev__systick_8c.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="preprocessor">#include &quot;<a class="code" href="dev__systick_8h.html">dev_systick.h</a>&quot;</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span> </div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">   25</a></span><span class="keyword">static</span> <span class="keyword">volatile</span> uint32_t <a class="code hl_variable" href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">Systick_Tick</a> = 0;</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span> </div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#ac816b9d61dad1fe749c8eb4c625320dd">   27</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="dev__systick_8c.html#ac816b9d61dad1fe749c8eb4c625320dd">systick_init</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span>{</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span>    <span class="comment">/* SystemFrequency / 1000  =&gt;  1ms中断一次 */</span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span>    <span class="keywordflow">if</span> (SysTick_Config(SystemCoreClock / 1000))</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span>    {</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>        <span class="comment">/* Capture error */</span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>        <span class="keywordflow">while</span> (1)</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span>            ;</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>    }</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span>}</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span> </div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#a15be0edddcb31507417fd4a2e62e67b8">   38</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="dev__systick_8c.html#a15be0edddcb31507417fd4a2e62e67b8">systick_stop</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span>{</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>    <span class="comment">/* Disable SysTick IRQ and SysTick Timer */</span></div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>    SysTick-&gt;CTRL &amp;= ~(SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk);</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>}</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span> </div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#a3d9798af743e2d9726406d6f847231ec">   44</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="dev__systick_8c.html#a3d9798af743e2d9726406d6f847231ec">systick_inc_tick</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>{</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>    ++<a class="code hl_variable" href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">Systick_Tick</a>;</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>}</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span> </div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#afdf1221fe41470afc9faf278a871b68c">   49</a></span>uint32_t <a class="code hl_function" href="dev__systick_8c.html#afdf1221fe41470afc9faf278a871b68c">systick_get_tick</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>{</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span>    <span class="keywordflow">return</span> <a class="code hl_variable" href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">Systick_Tick</a>;</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>}</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span> </div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#a3b0398a9543b1a7926f8739dadc61f96">   54</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="dev__systick_8c.html#a3b0398a9543b1a7926f8739dadc61f96">systick_delay_ms</a>(<span class="keyword">const</span> uint32_t ms)</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>{</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>    uint32_t tickstart = 0;</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>    <span class="keywordflow">for</span> (tickstart = <a class="code hl_variable" href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">Systick_Tick</a>; <a class="code hl_variable" href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">Systick_Tick</a> - tickstart &lt; ms;)</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>        ;</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span>}</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span> </div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"><a class="line" href="dev__systick_8c.html#aeafcf9df2bc3fe32a63d737a6f58afa4">   61</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="dev__systick_8c.html#aeafcf9df2bc3fe32a63d737a6f58afa4">systick_delay_us</a>(<span class="keyword">const</span> uint32_t us)</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>{</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>    <span class="comment">/* 不超过 ms */</span></div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span>    uint32_t reload = SysTick-&gt;LOAD;</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span>    uint32_t ticks = 0;</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span>    uint32_t told = 0, tnow = 0, tcnt = 0;</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>    <span class="comment">/* 获得延时经过的 tick 数 */</span></div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>    ticks = us * reload / 1000;</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>    <span class="comment">/* 获得当前时间 */</span></div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>    told = SysTick-&gt;VAL;</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span>    <span class="keywordflow">for</span> (;;)</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>    {</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>        <span class="comment">/* 循环获得当前时间, 直到达到指定的时间后退出循环 */</span></div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>        tnow = SysTick-&gt;VAL;</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>        <span class="keywordflow">if</span> (tnow != told)</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>        {</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>            tcnt += ((tnow &lt; told) ? (told - tnow) : (reload - tnow + told));</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>            told = tnow;</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>            <span class="keywordflow">if</span> (tcnt &gt;= ticks)</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>            {</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>                <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>            }</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>        }</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>    }</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>}</div>
<div class="ttc" id="adev__systick_8c_html_a15be0edddcb31507417fd4a2e62e67b8"><div class="ttname"><a href="dev__systick_8c.html#a15be0edddcb31507417fd4a2e62e67b8">systick_stop</a></div><div class="ttdeci">void systick_stop(void)</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00038">dev_systick.c:38</a></div></div>
<div class="ttc" id="adev__systick_8c_html_a3b0398a9543b1a7926f8739dadc61f96"><div class="ttname"><a href="dev__systick_8c.html#a3b0398a9543b1a7926f8739dadc61f96">systick_delay_ms</a></div><div class="ttdeci">void systick_delay_ms(const uint32_t ms)</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00054">dev_systick.c:54</a></div></div>
<div class="ttc" id="adev__systick_8c_html_a3d9798af743e2d9726406d6f847231ec"><div class="ttname"><a href="dev__systick_8c.html#a3d9798af743e2d9726406d6f847231ec">systick_inc_tick</a></div><div class="ttdeci">void systick_inc_tick(void)</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00044">dev_systick.c:44</a></div></div>
<div class="ttc" id="adev__systick_8c_html_ac816b9d61dad1fe749c8eb4c625320dd"><div class="ttname"><a href="dev__systick_8c.html#ac816b9d61dad1fe749c8eb4c625320dd">systick_init</a></div><div class="ttdeci">void systick_init(void)</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00027">dev_systick.c:27</a></div></div>
<div class="ttc" id="adev__systick_8c_html_aeafcf9df2bc3fe32a63d737a6f58afa4"><div class="ttname"><a href="dev__systick_8c.html#aeafcf9df2bc3fe32a63d737a6f58afa4">systick_delay_us</a></div><div class="ttdeci">void systick_delay_us(const uint32_t us)</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00061">dev_systick.c:61</a></div></div>
<div class="ttc" id="adev__systick_8c_html_af7f7e8212003d7f7362d66e422d98073"><div class="ttname"><a href="dev__systick_8c.html#af7f7e8212003d7f7362d66e422d98073">Systick_Tick</a></div><div class="ttdeci">static volatile uint32_t Systick_Tick</div><div class="ttdoc">SysTick ticks</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00025">dev_systick.c:25</a></div></div>
<div class="ttc" id="adev__systick_8c_html_afdf1221fe41470afc9faf278a871b68c"><div class="ttname"><a href="dev__systick_8c.html#afdf1221fe41470afc9faf278a871b68c">systick_get_tick</a></div><div class="ttdeci">uint32_t systick_get_tick(void)</div><div class="ttdef"><b>Definition:</b> <a href="dev__systick_8c_source.html#l00049">dev_systick.c:49</a></div></div>
<div class="ttc" id="adev__systick_8h_html"><div class="ttname"><a href="dev__systick_8h.html">dev_systick.h</a></div><div class="ttdoc">系统滴答定时器</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5
</small></address>
</body>
</html>
